package springboot.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author daiqiang
 * @since 2024/10/2-22:11
 */
@Configuration// 单体项目这么处理，，微服务不用管，网关统一处理跨域
public class CorsConfiguration implements WebMvcConfigurer {
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")//所有请求都允许跨域访问
                //允许所有域名访问
                .allowedOrigins("*")
                //允许所有的请求方法访问该跨域资源
                .allowedHeaders("*")
                //允许所有的请求方法访问该跨域资源
                .allowedMethods("GET", "POST", "DELETE", "PUT");
    }
}
